//
//  UIPageViewController+CLCategory.m
//  CLBrowser
//
//  Created by 梁慧聪 on 2022/7/26.
//

#import "UIPageViewController+CLCategory.h"
#import <objc/runtime.h>
static NSString *IsGestureRecognizerEnabled = @"IsGestureRecognizerEnabled";
static NSString *TapIsGestureRecognizerEnabled = @"TapIsGestureRecognizerEnabled";

@implementation UIPageViewController (CLCategory)
@dynamic tapGestureRecognizer;
- (void)setGestureRecognizerEnabled:(BOOL)gestureRecognizerEnabled {
    for (UIGestureRecognizer *ges in self.gestureRecognizers) {
        ges.enabled = gestureRecognizerEnabled;
    }
    objc_setAssociatedObject(self, &IsGestureRecognizerEnabled, @(gestureRecognizerEnabled), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (BOOL)gestureRecognizerEnabled {
    return [objc_getAssociatedObject(self, &IsGestureRecognizerEnabled) boolValue];
}

- (UITapGestureRecognizer *)tapGestureRecognizer {
    for (UIGestureRecognizer *ges in self.gestureRecognizers) {
        if ([ges isKindOfClass:[UITapGestureRecognizer class]]) {
            return (UITapGestureRecognizer *)ges;
        }
    }
    return nil;
}

- (void)setTapGestureRecognizerEnabled:(BOOL)tapGestureRecognizerEnabled {
    for (UIGestureRecognizer *ges in self.gestureRecognizers) {
        ges.enabled = tapGestureRecognizerEnabled;
    }
    objc_setAssociatedObject(self, &TapIsGestureRecognizerEnabled, @(tapGestureRecognizerEnabled), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (BOOL)tapGestureRecognizerEnabled {
    return [objc_getAssociatedObject(self, &TapIsGestureRecognizerEnabled) boolValue];
}
@end
